<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>FileHelpers Library - Marcos Meli</TITLE>
<LINK href="/favicon.ico" rel="SHORTCUT ICON"><LINK
href="global.css" type=text/css
rel=stylesheet>
<link type="text/css" rel="stylesheet" href="SyntaxHighlighter.css"></link>

<meta NAME="Description"        content="An easy to use .NET library to read/write data from fixed length or delimited files or streams. It has support to import/export data from different data sources." />
<meta name="Author"             content="Marcos Meli" />
<meta NAME="keywords" Content="filehelpers,CSV,Marcos_Meli,C#,free,opensource,Devoo.net,Delimited Files,Import/Export">
<meta NAME="Copyright" CONTENT="Copyright 2005-07 to Marcos Meli - www.Devoo.net. All Rights Reserved.">

<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
</HEAD>
<BODY   text=black vLink=purple aLink=red link=blue
bgColor=white leftMargin=0 topMargin=0>

		{$HEADER$}


<table width="100%" cellpadding="5" cellspacing="5">
<tr><td><div id=contentdiv>
<h2>Async Read  Example </h2>
<blockquote>
<p>If you have a source file like this, separated by a |:</p>
<blockquote>
<textarea name="code" class="c#:nogutter:nocontrols">
10248|VINET|04071996|32.38
10249|TOMSP|05071996|11.61
10250|HANAR|08071996|65.83
10251|VICTE|08071996|41.34
...............
</textarea>
</blockquote>
<p>You must declare a Record Mapping Class:</p>
<blockquote>
<textarea name="code" class="c#">
[DelimitedRecord(&quot;|&quot;)]
public class Orders
{
  public int OrderID;

  public string CustomerID;

  [FieldConverter(ConverterKind.Date, &quot;ddMMyyyy&quot;)]
  public DateTime OrderDate;

  public decimal Freight;
}
</textarea>
</blockquote>
<p>Finally you can do a record by record procesing:</p>
<blockquote>
<textarea name="code" class="c#">

FileHelperAsyncEngine engine = new FileHelperAsyncEngine(typeof(Orders));

engine.BeginReadFile(&quot;TestIn.txt&quot;);

// The engine is IEnumerable 
foreach(Orders ord in engine)
{
   // your code here
   Console.WriteLine(ord.CustomerID);
}

engine.Close();

</textarea>
</blockquote>
<p>The Async can be used like an IDIsposable object with the using directive:</p>
<blockquote>
<textarea name="code" class="c#">

using(FileHelperAsyncEngine engine = new FileHelperAsyncEngine(typeof(Orders)))
{
	engine.BeginReadFile(&quot;TestIn.txt&quot;);

	foreach(Orders ord in engine)
	{
	   // your code here
	}
} // Auto Closed

</textarea>
</blockquote>
<blockquote><blockquote>&nbsp;</blockquote>
</blockquote>
</blockquote>
		{$FOOTER$}
</tr>
</table>

</BODY></HTML>
